import { server } from "@/request/index";
//引用类型
import type { IResTradeType } from "./api";
//1、获取spu初始数据类型type
export interface recordsType {
  id: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number;
  spuSaleAttrList?: null;
  spuImageList?: null;
}

export type SpuListType = Omit<IResTradeType, "records"> & {
  records: recordsType[];
};

//spu图片列表type
export interface spuImageList {
  id?: number;
  spuId?: number;
  imgName: string;
  imgUrl: string;
}
//2、spu销售属性列表type
export interface spuSaleAttrValueListType {
  id?: number;
  spuId?: number;
  isChecked?: null;
  baseSaleAttrId: number;
  saleAttrName: string;
  saleAttrValueName: string;
}
//销售属性
export interface spuSaleAttrListType {
  id?: number;
  spuId?: number;
  baseSaleAttrId: number;
  saleAttrName: string;
  spuSaleAttrValueList: spuSaleAttrValueListType[];
}

//类型体操剔除并添加新类型type
export type SaveSpuInfoType = Omit<
  recordsType,
  "id" | "spuSaleAttrList" | "spuImageList"
> & {
  spuSaleAttrList: spuSaleAttrListType[];
  spuImageList: spuImageList[];
  id?: number;
};
//修改类型体操剔除并添加新类型type
// export type ChangeSpuInfoType = Omit<
//   recordsType,
//   "spuSaleAttrList" | "spuImageList"
// > & {
//   spuSaleAttrList: spuSaleAttrListType[];
//   spuImageList: spuImageList[];
// };

//1、获取spuList
export const reqSpuList = (
  category3Id: number,
  page: number = 1,
  limit: number = 5
) => {
  return server.get<any, SpuListType>(`/product/${page}/${limit}`, {
    params: { category3Id },
  });
};
// 2、添加
export const reqSaveSpuInfo = (data: SaveSpuInfoType) => {
  return server.post(`/product/saveSpuInfo`, data);
};
//修改
// export const reqChangeSpuInfo = (data: SaveSpuInfoType) => {
//   return server.post(`/product/updateSpuInfo`, data);
// };
//3、获取图片信息
export const reqSpuImgList = (id: number) => {
  return server.get<any, spuImageList[]>(`/product/spuImageList/${id}`);
};
//4、获取销售属性
export const reqSpuSaleAttrList = (id: number) => {
  return server.get<any, spuSaleAttrListType[]>(
    `product/spuSaleAttrList/${id}`
  );
};
//5、获取图片
export const reqSpuImageList = (id: number) => {
  return server.get(`/product/spuImageList/${id}`);
};
//6、删除
export const reqDeleteSpuItem = (id: number) => {
  return server.delete(`product/deleteSpu/${id}`);
};
